﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;
namespace StoreWeb.system.memberManage
{
    public partial class list : System.Web.UI.Page
    {
        BLL.member members = new BLL.member();
        Maticsoft.BLL.Orders bll = new Maticsoft.BLL.Orders();
        Maticsoft.BLL.UserAdmin user = new Maticsoft.BLL.UserAdmin();
        //BLL.Role role = new BLL.Role();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int totalOrders = members.GetRecordCount("");
                AspNetPager1.RecordCount = totalOrders;
                
            }
        }
        void bindData(string where)
        {


            if (where == "")
            {
                String loginname = user.GetModel(Convert.ToInt32(Request.Cookies["UserLogin"].Values[0])).loginname;//登录名
                String dealersid = user.GetModel(Convert.ToInt32(Request.Cookies["UserLogin"].Values[0])).dealersid;//经销商ID
                if (loginname == "admin")
                {//管理员查看全部
                    where = "";
                }
                else
                {
                    where += " dealersid='" + dealersid + "'";
                }

            }
            else 
            {
                String loginname = user.GetModel(Convert.ToInt32(Request.Cookies["UserLogin"].Values[0])).loginname;//登录名
                String dealersid = user.GetModel(Convert.ToInt32(Request.Cookies["UserLogin"].Values[0])).dealersid;//经销商ID
                if (loginname == "admin")
                {//管理员查看全部
                    where += "";
                }
                else
                {
                    where += " and dealersid='" + dealersid + "'";
                }
            }

            Repeater1.DataSource = members.GetListByPage(where, "", AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);
            Repeater1.DataBind();
        }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            bindData(hidwhere.Value);
        }

        /// <summary>
        /// 获得性别 0保密 1男 2女
        /// </summary>
        /// <param name="parentid"></param>
        /// <returns></returns>
        protected string GetsexName(String sex)
        {
            if (sex == "0")
            {
                return "保密";
            }
            else if (sex == "1")
            {
                return "男";
            }
            else if (sex == "2")
            {
                return "女";
            }
            else
            {
                return "";
            }
        }


        /// <summary>
        /// 获得类型  是否会员（0普通 1会员）
        /// </summary>
        /// <param name="parentid"></param>
        /// <returns></returns>
        protected string GetisvipName(String isvip)
        {
            if (isvip == "0")
            {
                return "普通";
            }
            else if (isvip == "1")
            {
                return "会员";
            }
            else
            {
                return "";
            }
        }


        /// <summary>
        /// 获得是否有消费订单流水
        /// </summary>
        /// <param name="parentid"></param>
        /// <returns></returns>
        protected string GetOrderNum(String membercode)
        {

            int OrderNum = bll.GetModelList(" membercode='" + membercode + "'").Count();
            if (OrderNum>0)
            {
                return "";
            }else{
                return "删除";
            }
        }

        protected void btnserach_Click(object sender, EventArgs e)
        {

            string where = "1=1 ";
            if (mmobile.Value != null && !string.IsNullOrEmpty(mmobile.Value))
            {
                where += " and mobile = '" + mmobile.Value + "'";
            }
            if (mname.Value != null && !string.IsNullOrEmpty(mname.Value))
            {
                where += " and name = '" + mname.Value + "'";
            }
            hidwhere.Value = where;
            bindData(hidwhere.Value);
        }

    }
}